package com.ruipengkj.component.jtable;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.SwingConstants;
import javax.swing.table.TableCellRenderer;

import com.ruipengkj.commons.util.Util;
import com.ruipengkj.factory.ImageFactory;

public class JTableHeaderImage extends JLabel implements TableCellRenderer {

	private static final long serialVersionUID = 1L;

	private Image img = ImageFactory.loadImage(ImageFactory.PANEL_DISH_TYPE_BG).getImage();
	private ImageIcon icon=ImageFactory.loadImage(ImageFactory.ICON_4);
	
	public JTableHeaderImage() {
		Util.setSize(this, 200, 39);
		this.setIcon(icon);
		setHorizontalAlignment(SwingConstants.LEFT);
//		setHorizontalTextPosition(SwingConstants.RIGHT);
//		setVerticalTextPosition(SwingConstants.CENTER);
	}
	
	@Override
	protected void paintComponent(Graphics g) {
		if (img != null) {
			int x = 0;
			int width = img.getWidth(null);
			if (width > 0) {
				while(true) {
					if (x > this.getWidth()) {
						break;
					}
					g.drawImage(img, x, -1, null);
					x += width;
				}
			}
		}
		super.paintComponent(g);
	}
	
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		this.setFont(Util.TABLE_HEADER_FONT);
        this.setText(value.toString());
        return this;
	}
}
